package com.zx.pay.wechat.controller;

import com.zx.pay.wechat.service.WeChatPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wechat/pay")
public class WeChatPayController {

    @Autowired
    private WeChatPayService weChatPayService;

    /**
     * JSAPI支付
     */
    @PostMapping("/jsapi")
    public com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse jsapiPay(@RequestParam String outTradeNo,
                                                                                                      @RequestParam String description,
                                                                                                      @RequestParam int amount,
                                                                                                      @RequestParam String openid) {
        return weChatPayService.jsapiPay(outTradeNo, description, amount, openid);
    }

    /**
     * APP支付
     */
    @PostMapping("/app")
    public com.wechat.pay.java.service.payments.app.model.PrepayResponse appPay(@RequestParam String outTradeNo,
                                                                                @RequestParam String description,
                                                                                @RequestParam int amount) {
        return weChatPayService.appPay(outTradeNo, description, amount);
    }

    /**
     * H5支付
     */
    @PostMapping("/h5")
    public com.wechat.pay.java.service.payments.h5.model.PrepayResponse h5Pay(@RequestParam String outTradeNo,
                                                                              @RequestParam String description,
                                                                              @RequestParam int amount,
                                                                              @RequestParam String ip) {
        return weChatPayService.h5Pay(outTradeNo, description, amount, ip);
    }

    /**
     * Native支付
     */
    @PostMapping("/native")
    public com.wechat.pay.java.service.payments.nativepay.model.PrepayResponse nativePay(@RequestParam String outTradeNo,
                                                                                         @RequestParam String description,
                                                                                         @RequestParam int amount) {
        return weChatPayService.nativePay(outTradeNo, description, amount);
    }

    /**
     * 小程序支付
     */
    @PostMapping("/mini-program")
    public com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse miniProgramPay(@RequestParam String outTradeNo,
                                                                                                            @RequestParam String description,
                                                                                                            @RequestParam int amount,
                                                                                                            @RequestParam String openid) {
        return weChatPayService.miniProgramPay(outTradeNo, description, amount, openid);
    }

    // 为了保持结构清晰，将不同支付场景的接口分散到不同的Controller中
    // JSAPI支付相关接口请查看 JsapiPayController
    // APP支付相关接口请查看 AppPayController
    // H5支付相关接口请查看 H5PayController
    // Native支付相关接口请查看 NativePayController
    // 小程序支付相关接口请查看 MiniProgramPayController
    // 退款相关接口请查看 RefundController
    // 账单相关接口请查看 BillController
}